//
//  ViewController.m
//  UI28-UIViewAnimation(二)
//
//  Created by 韩旭 on 16/8/22.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "ViewController.h"
#import "UIView+Frame.h"
@interface ViewController ()
@property (nonatomic, strong) UIView *viewAnimation;
@property (nonatomic, strong) UIButton *animationBtn;
@property (nonatomic, strong) UIButton *animationButtonTwo;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.animationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _animationBtn.backgroundColor = [UIColor blueColor];
    _animationBtn.frame = CGRectMake(0, 0, 100, 100);
    [self.view addSubview:_animationBtn];
    self.animationButtonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
    self.animationButtonTwo.backgroundColor = [UIColor greenColor];
    _animationButtonTwo.frame = CGRectMake(10, 10, 100, 100);
//    [self.view addSubview:_animationButtonTwo];
    [_animationBtn addTarget:self action:@selector(buttonChilked:) forControlEvents:UIControlEventTouchUpInside];
    self.viewAnimation = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    _viewAnimation.backgroundColor = [UIColor redColor];
    [self.view addSubview:_viewAnimation];
//   参数1.
//    参数2.
//    参数3。0.0 - 1.0  数值越小，阻力越小：数值越大阻力越大
//    参数4. 速度
//    参数5， 选项
    
    
   [UIView animateWithDuration:3 delay:0 usingSpringWithDamping:1.0f initialSpringVelocity:0.0f options:UIViewAnimationOptionCurveLinear animations:^{
       _viewAnimation.HX_width = 100;
       _viewAnimation.HX_height = 300;
       _viewAnimation.backgroundColor = [UIColor yellowColor];
   } completion:^(BOOL finished) {
       NSLog(@"动画完成了");
   }];
}
- (void)buttonChilked:(UIButton *)btn {
//    参数1：需要执行动画的view
//    参数2：持续时间；
//    参数3：动画效果
//    [UIView transitionWithView:_animationBtn duration:3 options:UIViewAnimationOptionTransitionCurlUp animations:^{
//        _animationBtn.HX_height = 100;
//    } completion:^(BOOL finished) {
////        动画可以嵌套的
//        [UIView animateWithDuration:0.5 animations:^{
//            _animationBtn.HX_height = 200;
//        }];
//    }];
    // toView added to fromView.superview, fromView removed from its superview
//    toVIew会被添加到fromView的父视图上，然后fromView被父视图移除掉
    [UIView transitionFromView:_animationBtn toView:_animationButtonTwo duration:3 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
        
        
    }];
    
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
